# encoding=utf-8
from Parents.Functions.GeneralFunction import GeneralFunction
from LBT.Resource.BaseAtt import BaseAtt
class BaseOperation(GeneralFunction,BaseAtt):
    """
    模块操作通用方法
    """
    def  selectWithInput(self,dr, cascadesort, inputsort, keys):
        """
        选择带有输入框的下拉框
        :param dr:驱动
        :param cascadesort:选择框
        :param inputsort:输入框
        :param keys:关键字,文字或者排序
        :return:
        """
        dr.find_elements_by_class_name(self.chosen_class)[cascadesort].click()
        if isinstance(keys, int):
            selectors = dr.find_elements_by_xpath(self.chosen_namelist_xpath)
            text=selectors[keys].text
            selectors[keys].click()
            return text
        else:
            dr.find_elements_by_class_name(self.chosen_input_class)[inputsort].send_keys(keys)
            selectors = dr.find_elements_by_xpath(self.chosen_namelist_xpath)
            for selector in selectors:
                if keys == selector.text:
                    selector.click()
            return keys
    def  selectWithOutInput(self,dr, cascadesort, keys,listxpath="",listsort=-1):
        """
        选择不带有输入框的下拉框
        :param dr:驱动
        :param cascadesort:选择框的排序，如果不是int，就传入element
        :param keys:关键字
        :param listxpath:选择列表的xpath
        :param listsort:列表的第几个选择
        :return:
        """
        if listxpath=="":
            listxpath=self.chosen_namelist_xpath
        if isinstance(cascadesort,int):
            ele=dr.find_elements_by_class_name(self.chosen_class)[cascadesort]
        else:
            ele=cascadesort
        dr.execute_script("arguments[0].focus();", ele)
        ele.click()
        selectors = dr.find_elements_by_xpath(listxpath)
        if not listsort==-1:
            keys=selectors[listsort].text
        for selector in selectors:
            if keys == selector.text:
                selector.click()
        return keys